using System;
using System.Data;
using System.Collections;
using System.Collections.Generic;

using Framework;

namespace SchemaMonitor
{
    [Serializable()]
    public partial class CPublishChapter : CBaseDynamic, IComparable<CPublishChapter>
    {
        #region Constructors
        //Public (Copy Constructor)
        public CPublishChapter(CPublishChapter original, CDataSrc target)
        {
            //Database Connection
            m_dataSrc = target;

            //Copy fields
            _pubChapPublishId = original.PubChapPublishId;
            _pubChapChapterId = original.PubChapChapterId;
            _pubChapWords = original.PubChapWords;
            _pubChapComments = original.PubChapComments;
            _pubChapPostId = original.PubChapPostId;
            _pubChapPostMs = original.PubChapPostMs;
            _pubChapCommentsPosted = original.PubChapCommentsPosted;
            _pubChapCommentsPostedMs = original.PubChapCommentsPostedMs;
        }

        //Protected (Datareader/Dataset)
        protected CPublishChapter(CDataSrc dataSrc, IDataReader dr) : base(dataSrc, dr) {}
        protected CPublishChapter(CDataSrc dataSrc, DataRow     dr) : base(dataSrc, dr) {}
        #endregion

        #region Default Values
        protected override void InitValues_Auto()
        {
            //Null-Equivalent values (except String.Empty, as nulls tend to be inconvenient for string types)
            _pubChapId = int.MinValue;
            _pubChapPublishId = int.MinValue;
            _pubChapChapterId = int.MinValue;
            _pubChapWords = int.MinValue;
            _pubChapComments = int.MinValue;
            _pubChapPostId = long.MinValue;
            _pubChapPostMs = long.MinValue;
            _pubChapCommentsPosted = int.MinValue;
            _pubChapCommentsPostedMs = long.MinValue;
        }
        #endregion

        #region Members
        protected int _pubChapId;
        protected int _pubChapPublishId;
        protected int _pubChapChapterId;
        protected int _pubChapWords;
        protected int _pubChapComments;
        protected long _pubChapPostId;
        protected long _pubChapPostMs;
        protected int _pubChapCommentsPosted;
        protected long _pubChapCommentsPostedMs;
        #endregion

        #region Properties - Column Values
        //Primary Key Column (ReadOnly)
        public int PubChapId    {   get { return _pubChapId;   } }

        //Table Columns (Read/Write)
        public int PubChapPublishId    {   get { return _pubChapPublishId; } set { _pubChapPublishId = value; }    }
        public int PubChapChapterId    {   get { return _pubChapChapterId; } set { _pubChapChapterId = value; }    }
        public int PubChapWords    {   get { return _pubChapWords; } set { _pubChapWords = value; }    }
        public int PubChapComments    {   get { return _pubChapComments; } set { _pubChapComments = value; }    }
        public long PubChapPostId    {   get { return _pubChapPostId; } set { _pubChapPostId = value; }    }
        public long PubChapPostMs    {   get { return _pubChapPostMs; } set { _pubChapPostMs = value; }    }
        public int PubChapCommentsPosted    {   get { return _pubChapCommentsPosted; } set { _pubChapCommentsPosted = value; }    }
        public long PubChapCommentsPostedMs    {   get { return _pubChapCommentsPostedMs; } set { _pubChapCommentsPostedMs = value; }    }

        //View Columns (ReadOnly)

        #endregion

        #region MustOverride Methods
        //Schema Information
        public const string TABLE_NAME      = "PublishChapters";
        public const string VIEW_NAME       = "";         //Used to override this.ViewName { get }
        public const string ORDER_BY_COLS   = "PubChapId";   //See the CompareTo method below (Sql-based sorting should match In-Memory sorting)
        public const string SORTING_COLUMN  = "";
        public override string TableName {    get { return TABLE_NAME; } }
        protected override string OrderByColumns {    get { return ORDER_BY_COLS; } }

        //CompareTo Interface (Default Sort Order)
        public int CompareTo(CPublishChapter other) {   return this.PubChapId.CompareTo(other.PubChapId) ;  }

        //Primary Key Information
        public const string PRIMARY_KEY_NAME = "PubChapId";
        protected override bool InsertPrimaryKey {  get { return false;    }   }
        protected override string PrimaryKeyName {  get { return PRIMARY_KEY_NAME;    }    }
        protected override object PrimaryKeyValue 
        {
              get { return _pubChapId; }
              set { _pubChapId = (int)value; }
        }

        //Factory Methods - Object
        protected override CBase MakeFrom(DataRow row)      {   return new CPublishChapter(this.DataSrc, row);  }
        protected override CBase MakeFrom(IDataReader dr)   {   return new CPublishChapter(this.DataSrc, dr);   }

        //Factory Methods - List
        protected override IList MakeList()                 {   return new CPublishChapterList();               }
        protected override IList MakeList(int capacity)     {   return new CPublishChapterList(capacity);       }

        //Convert from ADO to .Net
        protected override void ReadColumns(IDataReader dr)
        {
            _pubChapId = CAdoData.GetInt(dr, "PubChapId");
            _pubChapPublishId = CAdoData.GetInt(dr, "PubChapPublishId");
            _pubChapChapterId = CAdoData.GetInt(dr, "PubChapChapterId");
            _pubChapWords = CAdoData.GetInt(dr, "PubChapWords");
            _pubChapComments = CAdoData.GetInt(dr, "PubChapComments");
            _pubChapPostId = CAdoData.GetLong(dr, "PubChapPostId");
            _pubChapPostMs = CAdoData.GetLong(dr, "PubChapPostMs");
            _pubChapCommentsPosted = CAdoData.GetInt(dr, "PubChapCommentsPosted");
            _pubChapCommentsPostedMs = CAdoData.GetLong(dr, "PubChapCommentsPostedMs");
        }
        protected override void ReadColumns(DataRow dr)
        {
            _pubChapId = CAdoData.GetInt(dr, "PubChapId");
            _pubChapPublishId = CAdoData.GetInt(dr, "PubChapPublishId");
            _pubChapChapterId = CAdoData.GetInt(dr, "PubChapChapterId");
            _pubChapWords = CAdoData.GetInt(dr, "PubChapWords");
            _pubChapComments = CAdoData.GetInt(dr, "PubChapComments");
            _pubChapPostId = CAdoData.GetLong(dr, "PubChapPostId");
            _pubChapPostMs = CAdoData.GetLong(dr, "PubChapPostMs");
            _pubChapCommentsPosted = CAdoData.GetInt(dr, "PubChapCommentsPosted");
            _pubChapCommentsPostedMs = CAdoData.GetLong(dr, "PubChapCommentsPostedMs");
        }

        //Parameters for Insert/Update    
        protected override CNameValueList ColumnNameValues()
        {
            CNameValueList data = new CNameValueList();
            data.Add("PubChapId", CAdoData.NullVal(_pubChapId));
            data.Add("PubChapPublishId", CAdoData.NullVal(_pubChapPublishId));
            data.Add("PubChapChapterId", CAdoData.NullVal(_pubChapChapterId));
            data.Add("PubChapWords", CAdoData.NullVal(_pubChapWords));
            data.Add("PubChapComments", CAdoData.NullVal(_pubChapComments));
            data.Add("PubChapPostId", CAdoData.NullVal(_pubChapPostId));
            data.Add("PubChapPostMs", CAdoData.NullVal(_pubChapPostMs));
            data.Add("PubChapCommentsPosted", CAdoData.NullVal(_pubChapCommentsPosted));
            data.Add("PubChapCommentsPostedMs", CAdoData.NullVal(_pubChapCommentsPostedMs));
            return data;
        }
        #endregion

        #region Queries - SelectAll/SelectWhere (inherited methods, cast only)
        //Select Queries - Non-Paged
        public new CPublishChapterList SelectAll()                                                          {    return (CPublishChapterList)base.SelectAll();                              }
        public new CPublishChapterList SelectAll(string orderBy)                                            {    return (CPublishChapterList)base.SelectAll(orderBy);                       }
        public new CPublishChapterList SelectWhere(string colName, ESign sign, object colValue)             {    return (CPublishChapterList)base.SelectWhere(colName, sign, colValue);     }
        public new CPublishChapterList SelectWhere(CCriteria where)                                         {    return (CPublishChapterList)base.SelectWhere(where);                       }
        public new CPublishChapterList SelectWhere(CCriteriaList where)                                     {    return (CPublishChapterList)base.SelectWhere(where);                       }
        public new CPublishChapterList SelectWhere(CCriteriaList where, string tableOrJoin)                 {    return (CPublishChapterList)base.SelectWhere(where, tableOrJoin);          }
        public new CPublishChapterList SelectWhere(CCriteriaList where, string tableOrJoin, string orderBy) {    return (CPublishChapterList)base.SelectWhere(where, tableOrJoin, orderBy); }
        [Obsolete("Arbitrary where-clause is not necessary portable or safe from sql injection attacks. Consider using the parameterised query interfaces")]
        public new CPublishChapterList SelectWhere(string unsafeWhereClause)                                {    return (CPublishChapterList)base.SelectWhere(unsafeWhereClause);           }
        public     CPublishChapterList SelectById(int pubChapId)                              {    return (CPublishChapterList)base.SelectById(pubChapId);       }
        public     CPublishChapterList SelectByIds(List<int> ids)                        {    return (CPublishChapterList)base.SelectByIds(ids);                         }

        //Select Queries - Paged
        public new CPublishChapterList SelectAll(  CPagingInfo pi)                                              {    return (CPublishChapterList)base.SelectAll(  pi);                              }
        public new CPublishChapterList SelectWhere(CPagingInfo pi, string name, ESign sign, object value)       {    return (CPublishChapterList)base.SelectWhere(pi, name, sign, value);           }
        public new CPublishChapterList SelectWhere(CPagingInfo pi, CCriteria criteria)                          {    return (CPublishChapterList)base.SelectWhere(pi, criteria);                    }
        public new CPublishChapterList SelectWhere(CPagingInfo pi, CCriteriaList criteria)                      {    return (CPublishChapterList)base.SelectWhere(pi, criteria);                    }
        public new CPublishChapterList SelectWhere(CPagingInfo pi, CCriteriaList criteria, string viewOrJoin)   {    return (CPublishChapterList)base.SelectWhere(pi, criteria, viewOrJoin);        }
        public     CPublishChapterList SelectByIds(CPagingInfo pi, List<int> ids)            {    return (CPublishChapterList)base.SelectByIds(pi, ids);                         }

        //Select Queries - Transactional
        public new CPublishChapterList SelectAll(                                                                                           IDbTransaction tx)  {    return (CPublishChapterList)base.SelectAll(tx);                                                     }
        public new CPublishChapterList SelectAll(string orderBy,                                                                            IDbTransaction tx)  {    return (CPublishChapterList)base.SelectAll(orderBy,                                         tx);    }
        public new CPublishChapterList SelectWhere(string columnName,               object columnValue,                                     IDbTransaction tx)  {    return (CPublishChapterList)base.SelectWhere(columnName,              columnValue,          tx);    }
        public new CPublishChapterList SelectWhere(string columnName,   ESign sign, object columnValue,                                     IDbTransaction tx)  {    return (CPublishChapterList)base.SelectWhere(columnName,    sign,     columnValue,          tx);    }
        public new CPublishChapterList SelectWhere(                             CCriteria     criteria,                                     IDbTransaction tx)  {    return (CPublishChapterList)base.SelectWhere(               criteria,                       tx);    }
        public new CPublishChapterList SelectWhere(                             CCriteriaList criteria,                                     IDbTransaction tx)  {    return (CPublishChapterList)base.SelectWhere(               criteria,                       tx);    }
        public new CPublishChapterList SelectWhere(                             CCriteriaList criteria, string tableOrJoin,                 IDbTransaction tx)  {    return (CPublishChapterList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public new CPublishChapterList SelectWhere(                             CCriteriaList criteria, string tableOrJoin, string orderBy, IDbTransaction tx)  {    return (CPublishChapterList)base.SelectWhere(               criteria, tableOrJoin,          tx);    }
        public     CPublishChapterList SelectById(int pubChapId,                                                              IDbTransaction tx)  {    return (CPublishChapterList)base.SelectById(pubChapId,                         tx);    }
        public     CPublishChapterList SelectByIds(List<int> ids,                                                        IDbTransaction tx)  {    return (CPublishChapterList)base.SelectByIds(ids,                                           tx);    }

        //Select Queries - Stored Procs
        public new CPublishChapterList MakeList(string storedProcName,                             IDbTransaction txOrNull)    {   return (CPublishChapterList)base.MakeList(storedProcName,             txOrNull);  }
        public new CPublishChapterList MakeList(string storedProcName, object[] parameters,        IDbTransaction txOrNull)    {   return (CPublishChapterList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishChapterList MakeList(string storedProcName, CNameValueList parameters,  IDbTransaction txOrNull)    {   return (CPublishChapterList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishChapterList MakeList(string storedProcName, List<object> parameters,    IDbTransaction txOrNull)    {   return (CPublishChapterList)base.MakeList(storedProcName, parameters, txOrNull);  }
        public new CPublishChapterList MakeList(string storedProcName, int param1,                 IDbTransaction txOrNull)    {   return (CPublishChapterList)base.MakeList(storedProcName, param1,     txOrNull);  }
        public new CPublishChapterList MakeList(string storedProcName, string param1,              IDbTransaction txOrNull)    {   return (CPublishChapterList)base.MakeList(storedProcName, param1,     txOrNull);  }

        //Query Results
        protected new CPublishChapterList MakeList(DataSet              ds) { return (CPublishChapterList)base.MakeList(ds);        }
        protected new CPublishChapterList MakeList(DataTable            dt) { return (CPublishChapterList)base.MakeList(dt);        }
        protected new CPublishChapterList MakeList(DataRowCollection  rows) { return (CPublishChapterList)base.MakeList(rows);      }
        protected new CPublishChapterList MakeList(IDataReader          dr) { return (CPublishChapterList)base.MakeList(dr);        }
        protected new CPublishChapterList MakeList(object           drOrDs) { return (CPublishChapterList)base.MakeList(drOrDs);    }        
        protected new CPublishChapterList MakeList(byte[]             gzip) { return (CPublishChapterList)base.MakeList(gzip);      }
        #endregion

        #region Queries - SelectBy[FK] (user-nominated fk/bool columns)
        //Non-Paged
        public CPublishChapterList SelectByPublishId(int pubChapPublishId)    {    return SelectWhere(new CCriteriaList("PubChapPublishId", pubChapPublishId));    }
        public CPublishChapterList SelectByChapterId(int pubChapChapterId)    {    return SelectWhere(new CCriteriaList("PubChapChapterId", pubChapChapterId));    }
        public CPublishChapterList SelectByPostId(long pubChapPostId)    {    return SelectWhere(new CCriteriaList("PubChapPostId", pubChapPostId));    }

        //Paged
        public CPublishChapterList SelectByPublishId(CPagingInfo pi, int pubChapPublishId)    {    return SelectWhere(pi, new CCriteriaList("PubChapPublishId", pubChapPublishId));    }
        public CPublishChapterList SelectByChapterId(CPagingInfo pi, int pubChapChapterId)    {    return SelectWhere(pi, new CCriteriaList("PubChapChapterId", pubChapChapterId));    }
        public CPublishChapterList SelectByPostId(CPagingInfo pi, long pubChapPostId)    {    return SelectWhere(pi, new CCriteriaList("PubChapPostId", pubChapPostId));    }

        //Count
        public int SelectCountByPublishId(int pubChapPublishId)   {   return SelectCount(new CCriteriaList("PubChapPublishId", pubChapPublishId));     }
        public int SelectCountByChapterId(int pubChapChapterId)   {   return SelectCount(new CCriteriaList("PubChapChapterId", pubChapChapterId));     }
        public int SelectCountByPostId(long pubChapPostId)   {   return SelectCount(new CCriteriaList("PubChapPostId", pubChapPostId));     }

        //Transactional
        public CPublishChapterList SelectByPublishId(int pubChapPublishId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubChapPublishId", pubChapPublishId), tx);    }
        public CPublishChapterList SelectByChapterId(int pubChapChapterId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubChapChapterId", pubChapChapterId), tx);    }
        public CPublishChapterList SelectByPostId(long pubChapPostId, IDbTransaction tx)    {    return SelectWhere(new CCriteriaList("PubChapPostId", pubChapPostId), tx);    }
        #endregion

        #region ToXml
        protected override void ToXml_Autogenerated(System.Xml.XmlWriter w)
        {
            Store(w, "PubChapId", this.PubChapId);
            Store(w, "PubChapPublishId", this.PubChapPublishId);
            Store(w, "PubChapChapterId", this.PubChapChapterId);
            Store(w, "PubChapWords", this.PubChapWords);
            Store(w, "PubChapComments", this.PubChapComments);
            Store(w, "PubChapPostId", this.PubChapPostId);
            Store(w, "PubChapPostMs", this.PubChapPostMs);
            Store(w, "PubChapCommentsPosted", this.PubChapCommentsPosted);
            Store(w, "PubChapCommentsPostedMs", this.PubChapCommentsPostedMs);
        }
        #endregion

    }
}
